ui package com.example.mylianxi;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.example.mylianxi.Bean;

import java.util.List;

public class MyAdapter extends  BaseAdapter {
    private Context context1;
    private List<Bean> list1;
    private LayoutInflater inflater1;

    public MyAdapter(Context context, List<Bean> list){
        this.context1=context;
        this.list1=list;
        inflater1=LayoutInflater.from(context);
    }

    @Override
    public int getCount() { return list1.size(); }

    @Override
    public Object getItem(int position) {
        return list1.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView s = null,a=null;
        //ViewHolder holder=null;
        if (convertView==null){
            convertView=inflater1.inflate(R.layout.adapter,parent,false);
                //holder = new ViewHolder();
                s = convertView.findViewById(R.id.name);
                a = convertView.findViewById(R.id.price);
        }
        Bean bean = list1.get(position);
        s.setText(bean.getName());
        a.setText(bean.getPrice());

        return convertView;
    }
}
